﻿//-----------------------------------------------------------------------
// <copyright file="MoneyLabel.cs" company="Redmist">
//     Copyright (c) Damien T Smith. All rights reserved.
// </copyright>
// <author>Damien Smith</author>
//-----------------------------------------------------------------------

namespace Redmist.UsageMonitor.CustomControls
{
    using System.Drawing;
    using System.Windows.Forms;

    /// <summary>A custom label based on a System.Windows.Forms.Label that shows the text in red if the text value starts with a '$' character but doesn't equal "$0.00"</summary>
    public class MoneyLabel : Label
    {
        /// <summary>A System.Drawing.Color used for storing the initial ForeColor of the control so that it can be restored later.</summary>
        private Color initialForeColor;

        /// <summary>Sets the ForeColor to red if the text contains a positive monetary value when painting the control.</summary>
        /// <param name="e">A System.Windows.Forms.PaintEventArgs representing the paint event arguments.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (!this.DesignMode)
            {
                if (this.Text.StartsWith("$") && this.Text != "$0.00")
                {
                    if (this.initialForeColor == Color.Empty)
                    {
                        this.initialForeColor = this.ForeColor;
                    }

                    this.ForeColor = Color.Red;
                }
                else if (this.initialForeColor != Color.Empty)
                {
                    this.ForeColor = this.initialForeColor;
                }
            }

            base.OnPaint(e);
        }
    }
}
